package com.init.iblog.Controller;

import com.init.iblog.domain.ResponseResult;
import com.init.iblog.domain.dto.BlogDto;
import com.init.iblog.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/article")
public class ArticleController {

    @Autowired
    private BlogService blogService;

    /**
     * 添加博客
     * @param blogDto
     * @return
     */
    @PostMapping
    public ResponseResult add(@RequestBody BlogDto blogDto){
        System.out.println(blogDto);
        System.out.println("===========进入添加博客接口/content/article============");
        return blogService.addArticle(blogDto);
    }

    /**
     * 分页查询文章列表
     * @param pageNum
     * @param pageSize
     * @param title
     * @param summary
     * @return
     */
    @GetMapping("/list")
    public ResponseResult getBlogList(Integer pageNum, Integer pageSize,String title,String summary){
        System.out.println("=============进入分页查询文章列表接口===============");
        return blogService.getArticleListPage(pageNum,pageSize,title,summary);
    }


    /**
     * 查询文章详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult getArticleDetail(@PathVariable Long id){
        System.out.println("=========进入查询文章详情接口===========");
        return blogService.getArticleDetail(id);
    }


    /**
     * 博客更新
     * @param blogDto
     * @return
     */
    @PutMapping
    public ResponseResult updateArticle(@RequestBody BlogDto blogDto){
        System.out.println("========进入博客更新接口=========");
        return blogService.updateArticle(blogDto);
    }


    @DeleteMapping("/{id}")
    public ResponseResult deleteArticle(@PathVariable Long id){
        System.out.println("========进入删除博客接口===========");
        return blogService.deleteArticle(id);
    }


}
